#! /bin/bash

source /etc/profile
if [ -n "$1" ]
then
do_date=$1
else
do_date=`date -d "-1 day" +%F`
fi

sql="
insert overwrite table test.dim_shops_his
select shopid,
shopname,
cityid,
cityname,
regionid,
regionname,
create_date,
start_date,
end_date
from test.dim_shops_his
where end_date < "$do_date"
union all
select shopid,
shopname,
cityid,
cityname,
regionid,
regionname,
create_date,
start_date,
'9999-12-31' as end_date
from test.dim_shops_his
where start_date <= '$do_date' and end_date >= '$do_date';
"
hive -e "$sql"
